package cn.iocoder.yudao.module.system.dal.mysql.merchant;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.app.merchant.vo.AppFellowReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.merchant.FellowMerchantDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface FellowMerchantMapper extends BaseMapperX<FellowMerchantDO> {

    default void deleteByIdAndMerchantId(Long userId, Long merchantId) {
        update(new LambdaUpdateWrapper<FellowMerchantDO>()
                .eq(FellowMerchantDO::getUserId, userId)
                .eq(FellowMerchantDO::getMerchantId, merchantId)
                .set(FellowMerchantDO::getDeleted, true));

    }


    default PageResult<FellowMerchantDO> selectPage(AppFellowReqVO reqVO) {

        return selectPage(reqVO, new LambdaQueryWrapperX<FellowMerchantDO>()
                .eqIfPresent(FellowMerchantDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(FellowMerchantDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(FellowMerchantDO::getId));

    }

    default FellowMerchantDO selectByMerchantAndUser(Long merchantId, Long userId) {
        return selectOne(new LambdaQueryWrapperX<FellowMerchantDO>()
                .eq(FellowMerchantDO::getMerchantId, merchantId)
                .eq(FellowMerchantDO::getUserId, userId));
    }

}
